// pages/ding_dan_manage/ding_dan_manage.js
import {
  request
} from "../../utils/http.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dingdan: 1,
    text:"",
    list: [],
    weifukuan: [{
        shijian: "2013/10/28",
        image: "http://122.51.84.231:9001/dianshang/冈田纱佳.jpg",
        mingzi: "冈田纱佳",
        tihuoshijian: "8月20号",
        number: "2",
        price: "169",
      },
      {
        shijian: "2024/11/17",
        image: "http://122.51.84.231:9001/dianshang/炮姐.jpg",
        mingzi: "炮姐",
        tihuoshijian: "5月21号",
        number: "5",
        price: "5000",
      }

    ],
    yitihuo: [{
        shijian: "2013/10/28",
        image: "http://122.51.84.231:9001/dianshang/冈田纱佳.jpg",
        mingzi: "冈田纱佳",
        tihuoshijian: "8月20号",
        number: "2",
        price: "169",
      },
      {
        shijian: "2024/11/17",
        image: "http://122.51.84.231:9001/dianshang/炮姐.jpg",
        mingzi: "炮姐",
        tihuoshijian: "5月21号",
        number: "5",
        price: "5000",
      }

    ]

  },
  onSearch(e) {
    this.setData({
      text:e.detail
    })
    if(this.data.dingdan==0){
      request({
        url: "/dianshang/orders/listGoods?userid=" + getApp().globalData.userInfo.userId+"&name="+e.detail,
        header: {
          "authorization": getApp().globalData.authorization
        }
      }).then(data => {
        // console.log(data);
        data.total=data.rows.length;
        this.setData({
          list: data
        })
      })
    }else{
      request({
        url: "/dianshang/orders/listGoods?userid=" + getApp().globalData.userInfo.userId + "&status=" + this.data.dingdan +"&name="+e.detail,
        header: {
          "authorization": getApp().globalData.authorization
        }
      }).then(data => {
        // console.log(data);
        data.total=data.rows.length;
        this.setData({
          list: data
        })
      })
    }
  },
  to(e) {
    wx.switchTab({
      url: e.currentTarget.id
    })
  },
  tihuo(e){
    request({
      url:"/dianshang/orders",
      method:"PUT",
      data:{
        id:e.currentTarget.id,
        status:3
      },
      header: {
        "authorization": getApp().globalData.authorization
      }
    }).then((data)=>{
      // console.log(data);
      if(data.code==200){
        wx.showModal({
          title: data.msg,
          showCancel: false
        })
        this.data.list.rows.map((item)=>{
          if(item.id==e.currentTarget.id)item.status=3;
          return item;
        })
        this.setData({
          list:this.data.list
        })
      }
    })
  },

  back() {
    wx.navigateBack();
  },
  dingdan(e) {
    // console.log(e);
    this.setData({
      dingdan: e.currentTarget.id
    })
    if(this.data.dingdan==0){
      request({
        url: "/dianshang/orders/listGoods?userid=" + getApp().globalData.userInfo.userId+"&name="+this.data.text,
        header: {
          "authorization": getApp().globalData.authorization
        }
      }).then(data => {
        // console.log(data);
        data.total=data.rows.length;
        this.setData({
          list: data
        })
      })
    }else{
      request({
        url: "/dianshang/orders/listGoods?userid=" + getApp().globalData.userInfo.userId + "&status=" + this.data.dingdan +"&name="+this.data.text,
        header: {
          "authorization": getApp().globalData.authorization
        }
      }).then(data => {
        // console.log(data);
        data.total=data.rows.length;
        this.setData({
          list: data
        })
      })
    }
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      dingdan: options.dingdan
    });
    if (options.dingdan == 0) {
      request({
        url: "/dianshang/orders/listGoods?userid=" + getApp().globalData.userInfo.userId,
        header: {
          "authorization": getApp().globalData.authorization
        }
      }).then(data => {
        this.setData({
          list: data
        })
      })
    } else {
      request({
        url: "/dianshang/orders/listGoods?userid=" + getApp().globalData.userInfo.userId + "&status=" + options.dingdan,
        header: {
          "authorization": getApp().globalData.authorization
        }
      }).then(data => {
        this.setData({
          list: data
        })
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  gobuy(e){
    console.log(e.currentTarget.id);
    console.log(this.data.list);
    wx.setStorageSync("dingdan",[this.data.list.rows[e.currentTarget.id].id]);
    wx.navigateTo({
      url: `/pages/go_wu_che_gopay/go_wu_che_gopay?money=`+this.data.list.rows[e.currentTarget.id].money,
    })
  }
})